package cn.audit.repository.log;

import cn.audit.bean.dto.UserCorrelation;
import cn.audit.bean.pojo.OperationLog;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


/**
 * @Author: 李忆枫
 * @Date: 2019/5/22 10:58
 */
public interface OperationLogRepository extends JpaRepository<OperationLog, Long>, JpaSpecificationExecutor<OperationLog> {


    /**
     * 关联查询
     *
     * @return
     */
    @Query(value = "select new cn.audit.bean.dto.UserCorrelation(u,a,o) " +
            "from OperationLog o,User u,AuditInstitution a " +
            "where o.units = a.id and o.userId = u.id " +
            "and (?1=null or u.name like %?1%) " +
            "and (?2=null or a.auditname like %?2%) " +
            "and (?3=null or o.module like %?3%) " +
            "and (?4=null or o.content like %?4%)")
    Page<UserCorrelation> findLogAll(String name, String auditname, String module, String content, Pageable page);

}
